package edu.cmu.ece.ds.droidchat.message;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.HashMap;

import android.util.Log;

/* Number 3
 * From: init user
 * To: user that is being invited
 * Purpose: send message to invite somebody to create a session
 * including the sender's username and receiver's username
 * entire message are encrypted, see encrypt create session invitation message
 */

public class CreateSessionInvitationMessage extends CreateSessionMessage implements
	Serializable {

	private static final long serialVersionUID = -4722752785141784965L;
	
	// username of the inviter
	private String senderUsername;
	
	// username of the invitee
	private String receiverUsername;
	
	// chat session id is a field of the parent class
	// private String chatSessionID;
	
	// tells the invitee if this invitation is just 1-on-1
	private boolean oneOnone = true;
	
	// tells the invitee who is already in the chat session
	//  valid only if oneOnone is false
	private HashMap<String, Integer> existingParticipants;

	/*private BigInteger publicModulus;
	private BigInteger publicExponent;*/
	
	// these two fields are only meaningful when 'oneOnone' is false
	private int t = -1;

	//user name that you want encrypted with the private key
	public CreateSessionInvitationMessage(String chatSessionid,
			String self, String invited, BigInteger mod, BigInteger exp) {
		super(chatSessionid);
		senderUsername = self;
		receiverUsername = invited;
		/*publicModulus = mod;
		publicExponent = exp;*/
//		Log.e("in invitation con mod is " + publicModulus.toString(),
//				""+publicModulus.bitCount());
		/*Log.e("in invitation con exp is " + publicExponent.toString()
				,""+publicExponent.bitCount());*/
	}
	
	public String getSenderUsername() {
		return senderUsername;
	}
	public String getReceiverUsername() {
		return receiverUsername;
	}
	/*public BigInteger getPublicModulus() {
		return publicModulus;
	}*/
	/*public BigInteger getPublicExponent() {
		return publicExponent;
	}*/
	
	// is this invitation for 1-on-1 chat session
	public boolean isOneOnone() {
		return oneOnone;
	}
	// specify if this invitation is for 1-on-1 chat session
	public void setOneOnone(boolean oneOnone) {
		this.oneOnone = oneOnone;
	}
	
	public HashMap<String, Integer> getExistingParticipants() {
		return existingParticipants;
	}
	public void setExistingParticipants(
			HashMap<String, Integer> existingParticipants) {
		this.existingParticipants = existingParticipants;
	}
	
	public boolean equals(CreateSessionInvitationMessage other){
		if(this.chatSessionID.equals(other.chatSessionID) &&
				this.getSenderUsername().equals(other.getSenderUsername())){
			return true;
		}
		return false;
	}
	
	public int getT() {
		return t;
	}
	public void setT(int t) {
		this.t = t;
	}
}
